﻿@using LeadMaster.Properties;
@using LeadMaster.Models;
@using LeadMaster.Controllers;
@model IEnumerable<LeadMaster.Models.Companies>

<img src="~/Images/create.png" class="leadwizard navbuttons boxtitle" />

<label class="boxtitle">Leads</label>

<table class="listtable contactstable" cellspacing="0" cellpadding="0">
<thead>
    <tr>
        <th class="tableheader clickcolumn" id="leadtype">
            Lead Type
        </th>
        <th class="tableheader">
            Contact
        </th>
        <th class="tableheader">
            @Html.DisplayNameFor(model => model.Telephone)
        </th>

        <th class="tableheader">
            @Html.DisplayNameFor(model => model.Company)
        </th>
        <th class="tableheader">
            @Html.DisplayNameFor(model => model.Town)
        </th>
        <th class="tableheader">
            @Html.DisplayNameFor(model => model.Postcode)
        </th>
    

        <th class="tableheader" width="70px"></th>
    </tr>
</thead>
<tbody>
@foreach (var item in Model)
{
    if (item.CompanyID > 1)
    {   
    <tr style="color: @(CompaniesController.GetColourCode(item.CompanyID)); background-color: #FFFFFF;">
        <td>
            @Html.DisplayFor(modelItem => item.LeadTypes.FirstOrDefault().Sector.Sector)
        </td>
        <td>
        @if (item.Contacts.Count > 0)
        {
            <label id="contact@(item.Contacts.FirstOrDefault().ContactID)" class="editcontactcompanyindex" style="cursor: pointer;color: @(CompaniesController.GetColourCode(item.CompanyID)); background-color: #FFFFFF;">
            @item.Contacts.FirstOrDefault().Forename @item.Contacts.FirstOrDefault().Surname
            </label>
        }
        else
        {
            @:&nbsp;
        }
        </td>
        <td>
            <img src="../../Images/page_add.png"/>
            @Html.DisplayFor(modelItem => item.Telephone)
        </td>
        <td style="vertical-align: middle; text-align: center; " >
            <!--<label  id="diary@(item.CompanyID)" class="diary" style="cursor: pointer;">@item.Company</label>-->
            <label class="editcompany navbuttons" id="edit@(item.CompanyID)"  style="color: @(CompaniesController.GetColourCode(item.CompanyID)); background-color: #FFFFFF;">@item.Company</label>
        </td>

        <td>
            @Html.DisplayFor(modelItem => item.Town)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Postcode)
        </td>
        <td width="70px">
            <img src="~/Images/comms.png" class="showenquiries" id="showenquiries@(item.CompanyID)" style="width: 25px; height: 25px; cursor: pointer; vertical-align: middle;" alt="Enquiries" />
            <!--<img src="~/Images/phone_icon.png" class="enquirycompany" id="enquiry@(item.CompanyID)" style="width: 25px; height: 25px; cursor: pointer; vertical-align: middle;" alt="Make Enquiry" />-->
            <!--<img src="~/Images/information.png" class="companydetails navbuttons"   id="details@(item.CompanyID)" />-->
            <img src="~/Images/user_add.png"    class="companyadduser navbuttons"   id="useradd@(item.CompanyID)" />
            <!--<img src="~/Images/Edit.png" class="editcompany navbuttons" id="edit@(item.CompanyID)" style="width: 15px; height: 15px; cursor: pointer;" alt="Edit Company" />-->
        </td>
    </tr>
    }

}
</tbody>
</table>

<div id="companieseditdialog" class="overlay">
</div>

<div id="companiesdetailsdialog" class="overlay">
</div>

<div id="companiesadduserdialog" class="overlay">
</div>

<div id="companiescreatedialog" class="overlay">
</div>

<div id="diarydialog" class="overlay">
</div>

<div id="showenquiriesdialog" class="overlay">
</div>

<div id="editcontactdialog" class="overlay">
</div>

<div id="wizarddialog" class="overlay">
</div>

<script type="text/javascript">
    $(document).ready(function () {

        $(".showenquiries").click(function () {
            var id = $(this).attr('id').substring(13);
            $("#showenquiriesdialog").html('<div style="text-align: center;"><div><img src="@Url.Content("~/Images/ajaxspinner_large.gif")" alt="Loading..." style="margin: 20px;" /></div><div>Loading...</div></div>');
            $('#showenquiriesdialog').load('@(Url.Action("ShowEnquiries", "Enquiry"))/' + id,
            function () {
                $("#showenquiriesdialog").dialog("close");
                $("#showenquiriesdialog").dialog(
                {
                    autoOpen: true,
                    width: 1100,
                    height: 800,
                    open: function () { $(".ui-dialog").css("box-shadow", "#000 5px 5px 5px"); },
                    position: { my: 'center', at: 'center', of: window },
                    modal: true,
                    resizable: false,
                    draggable: false,
                    dialogClass: 'notitle'
                });
            });
            $("#showenquiriesdialog").dialog(
            {
                autoOpen: true,
                width: 200,
                position: { my: 'center', at: 'center', of: window },
                modal: true,
                resizable: false,
                draggable: false,
                dialogClass: 'notitle'
            });
        });

        $(".editcompany").click(function () {
            var id = $(this).attr('id').substring(4);
            $("#companieseditdialog").html('<div style="text-align: center;"><div><img src="@Url.Content("~/Images/ajaxspinner_large.gif")" alt="Loading..." style="margin: 20px;" /></div><div>Loading...</div></div>');
            $('#companieseditdialog').load('@(Url.Action("Edit", "Companies"))/' + id,
        function () {
            $("#companieseditdialog").dialog("close");
            $("#companieseditdialog").dialog(
            {
                autoOpen: true,
                width: 900,
                open: function () { $(".ui-dialog").css("box-shadow", "#000 5px 5px 5px"); },
                position: { my: 'center', at: 'center', of: window },
                modal: true,
                resizable: false,
                draggable: false,
                dialogClass: 'notitle'
            });
        });
            $("#companieseditdialog").dialog(
            {
                autoOpen: true,
                width: 200,
                position: { my: 'center', at: 'center', of: window },
                modal: true,
                resizable: false,
                draggable: false,
                dialogClass: 'notitle'
            });
        });

        $(".companydetails").click(function () {
            var id = $(this).attr('id').substring(7);
            $("#companiesdetailsdialog").html('<div style="text-align: center;"><div><img src="@Url.Content("~/Images/ajaxspinner_large.gif")" alt="Loading..." style="margin: 20px;" /></div><div>Loading...</div></div>');
            $('#companiesdetailsdialog').load('@(Url.Action("Details", "Companies"))/' + id,
            function () {
                $("#companiesdetailsdialog").dialog("close");
                $("#companiesdetailsdialog").dialog(
                {
                    autoOpen: true,
                    width: 1000,
                    open: function () { $(".ui-dialog").css("box-shadow", "#000 5px 5px 5px"); },
                    position: { my: 'center', at: 'center', of: window },
                    modal: true,
                    resizable: false,
                    draggable: false,
                    dialogClass: 'notitle'
                });
            });
            $("#companiesdetailsdialog").dialog(
                {
                    autoOpen: true,
                    width: 200,
                    position: { my: 'center', at: 'center', of: window },
                    modal: true,
                    resizable: false,
                    draggable: false,
                    dialogClass: 'notitle'
                });
        });

        $(".companyadduser").click(function () {
            var companyID = $(this).attr('id').substring(7);
            $("#companiesadduserdialog").html('<div style="text-align: center;"><div><img src="@Url.Content("~/Images/ajaxspinner_large.gif")" alt="Loading..." style="margin: 20px;" /></div><div>Loading...</div></div>');
            $('#companiesadduserdialog').load('@(Url.Action("CreateWithCompany", "Contacts"))/' + companyID,
            function () {
                $("#companiesadduserdialog").dialog("close");
                $("#companiesadduserdialog").dialog(
                {
                    autoOpen: true,
                    width: 1000,
                    open: function () { $(".ui-dialog").css("box-shadow", "#000 5px 5px 5px"); },
                    position: { my: 'center', at: 'center', of: window },
                    modal: true,
                    resizable: false,
                    draggable: false,
                    dialogClass: 'notitle'
                });
            });
            $("#companiesadduserdialog").dialog(
                {
                    autoOpen: true,
                    width: 200,
                    position: { my: 'center', at: 'center', of: window },
                    modal: true,
                    resizable: false,
                    draggable: false,
                    dialogClass: 'notitle'
                });
        });

        $(".leadwizard").click(function () {
            $("#wizarddialog").html('<div style="text-align: center;"><div><img src="@Url.Content("~/Images/ajaxspinner_large.gif")" alt="Loading..." style="margin: 20px;" /></div><div>Loading...</div></div>');
            $('#wizarddialog').load('@(Url.Action("LeadWizard", "Leads"))',
                function () {
                    $("#wizarddialog").dialog("close");
                    $("#wizarddialog").dialog(
                {
                    autoOpen: true,
                    width: 900,
                    open: function () { $(".ui-dialog").css("box-shadow", "#000 5px 5px 5px"); },
                    position: { my: 'center', at: 'center', of: window },
                    modal: true,
                    resizable: false,
                    draggable: false,
                    dialogClass: 'notitle'
                });
                });
            $("#wizarddialog").dialog(
                {
                    autoOpen: true,
                    width: 200,
                    position: { my: 'center', at: 'center', of: window },
                    modal: true,
                    resizable: false,
                    draggable: false,
                    dialogClass: 'notitle'
                });
        });

        $(".diary").click(function () {
            var id = $(this).attr('id').substring(5);
            $("#diarydialog").html('<div style="text-align: center;"><div><img src="@Url.Content("~/Images/ajaxspinner_large.gif")" alt="Loading..." style="margin: 20px;" /></div><div>Loading...</div></div>');
            $('#diarydialog').load('@(Url.Action("Create", "Diary"))/' + id,
                function () {
                    $("#diarydialog").dialog("close");
                    $("#diarydialog").dialog(
                    {
                        autoOpen: true,
                        width: 900,
                        open: function () { $(".ui-dialog").css("box-shadow", "#000 5px 5px 5px"); },
                        position: { my: 'center', at: 'center', of: window },
                        modal: true,
                        resizable: false,
                        draggable: false,
                        dialogClass: 'notitle'
                    });
                });
            $("#diarydialog").dialog(
                {
                    autoOpen: true,
                    width: 200,
                    position: { my: 'center', at: 'center', of: window },
                    modal: true,
                    resizable: false,
                    draggable: false,
                    dialogClass: 'notitle'
                });
        });

        $(".enquirycompany").click(function () {
            var id = $(this).attr('id').substring(7);
            $("#enquirydialog").html('<div style="text-align: center;"><div><img src="@Url.Content("~/Images/ajaxspinner_large.gif")" alt="Loading..." style="margin: 20px;" /></div><div>Loading...</div></div>');
            $('#enquirydialog').load('@(Url.Action("Create", "Enquiry"))/' + id,
            function () {
                $("#enquirydialog").dialog("close");
                $("#enquirydialog").dialog(
                {
                    autoOpen: true,
                    width: 900,
                    open: function () { $(".ui-dialog").css("box-shadow", "#000 5px 5px 5px"); },
                    position: { my: 'center', at: 'center', of: window },
                    modal: true,
                    resizable: false,
                    draggable: false,
                    dialogClass: 'notitle'
                });
            });
            $("#enquirydialog").dialog(
            {
                autoOpen: true,
                width: 200,
                position: { my: 'center', at: 'center', of: window },
                modal: true,
                resizable: false,
                draggable: false,
                dialogClass: 'notitle'
            });
        });

        $(".editcontactcompanyindex").click(function () {
            var id = $(this).attr('id').substring(7);
            $("#editcontactdialog").html('<div style="text-align: center;"><div><img src="@Url.Content("~/Images/ajaxspinner_large.gif")" alt="Loading..." style="margin: 20px;" /></div><div>Loading...</div></div>');
            $('#editcontactdialog').load('@(Url.Action("Edit", "Contacts"))/' + id,
            function () {
                $("#editcontactdialog").dialog("close");
                $("#editcontactdialog").dialog(
                {
                    autoOpen: true,
                    width: 1000,
                    open: function () { $(".ui-dialog").css("box-shadow", "#000 5px 5px 5px"); },
                    position: { my: 'center', at: 'center', of: window },
                    modal: true,
                    resizable: false,
                    draggable: false,
                    dialogClass: 'notitle'
                });
            });
            $("#editcontactdialog").dialog(
            {
                autoOpen: true,
                width: 200,
                position: { my: 'center', at: 'center', of: window },
                modal: true,
                resizable: false,
                draggable: false,
                dialogClass: 'notitle'
            });
        });

        $("#leadtype").click(function () {
            $("#leadslist").html('<div style="text-align: center;"><div><img src="@Url.Content("~/Images/ajaxspinner_large.gif")" alt="Loading..." style="margin: 20px;" /></div><div>Loading...</div></div>');
            $('#leadslist').load('@(Url.Action("GroupLeadType", "Companies"))');
        });
    });
</script>